package com.yanqu.road.server.cmd.zhaoshang;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.pb.zhaoshang.ZhaoShangProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.zhaoshang.ZsConfigMgr;
import com.yanqu.road.server.manger.zhaoshang.ZsMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_ZS_PROJECT_SIMPLE_LIST, desc = "项目榜")
public class ZsProjectSimpleListCmd extends AbstractCommand {

    private int templateId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ZhaoShangProto.ZsProjectSimpleListReqMsg reqMsg = ZhaoShangProto.ZsProjectSimpleListReqMsg.parseFrom(packet.getBytes());
        templateId = reqMsg.getTemplateId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(!SystemOpenMgr.systemOpen(player, eSystemId.ZhaoShang.getValue())){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }

        if(!ZsMgr.isZsSystemOpenTime()){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }


        //直接上跨服查找
        ZhaoShangProto.CrossZsProjectListReqMsg.Builder crossReqMsg = ZhaoShangProto.CrossZsProjectListReqMsg.newBuilder();
        crossReqMsg.setListNumLimit(ZsConfigMgr.getZsListSize());
        crossReqMsg.setSearchUserAliasId(0);
        crossReqMsg.setTemplateId(templateId);
        crossReqMsg.setGroupId(ZsMgr.getGroupId(GameServer.getInstance().getServerId()));  //分组id
        player.sendPacket(CrossProtocol.C2_ZHAO_SHANG_PROJECT_LIST, crossReqMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
